package com.sydx.service;

import com.github.pagehelper.PageHelper;
import com.sydx.dao.ParkDao;
import com.sydx.entity.Park;
import com.sydx.utils.BeanMapUtils;
import com.sydx.utils.MapParameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @Author zoutr
 * @Description
 * @Date 2021/6/29
 **/
@Service
public class ParkService {

    @Autowired
    private ParkDao parkDao;

    public int create(Park pi) {
        return parkDao.create(pi);
    }

    public int delete(Integer id) {
        // 原本这样写每次都要创建map,增加了耦合性，所以创建一个MapParameter工具类，直接调用
       /* HashMap<String, Object> map = new HashMap<>();
        map.put("id", id);
        return clazzDao.delete(map);*/
        return parkDao.delete(MapParameter.getInstance().addId(id).getMap());
    }

    public int delete(String ids) {
        int flag = 0;
        for (String str : ids.split(",")) {
            flag = parkDao.delete(MapParameter.getInstance().addId(Integer.parseInt(str)).getMap());
        }
        return flag;
    }

    public int update(Park park ) {
        Map<String,Object> map = MapParameter.getInstance()
                .add(BeanMapUtils.beanToMapForUpdate(park ))
                .addId(park .getId()).getMap();
        return parkDao.update(map);
    }

    public List<Park> query(Park park)  {
        /*分页查询*/
        if (park != null && park.getPage() != null) {
            PageHelper.startPage(park.getPage(),park.getLimit());
        }
        return parkDao.query(BeanMapUtils.beanToMap(park));
    }

    public Park detail(Integer id) {

        return parkDao.detail(MapParameter.getInstance().addId(id).getMap());
    }

    public int count(Park park) {

        return parkDao.count(BeanMapUtils.beanToMap(park));
    }


}
